/**
 * 文件名：HashedCredentialsMatcherV2.java
 *
 * 创建人：Fyh - 1009173473@qq.com
 *
 * 创建时间：2020年4月22日 上午9:25:39
 *
 * 版权所有：南京植百汇智能科技服务有限公司
 */
package com.jeeplus.modules.sys.security;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;

/**
 * [描述信息：说明类的基本功能]
 *
 * @author Fyh - 1009173473@qq.com
 * @version 1.0 Created on 2020年4月22日 上午9:25:39
 */
public class HashedCredentialsMatcherV2 extends HashedCredentialsMatcher {

	public HashedCredentialsMatcherV2() {
		super();
	}

	public HashedCredentialsMatcherV2(String hashAlgorithmName) {
		super(hashAlgorithmName);
	}

	@Override
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {

		UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;
		if (usernamePasswordToken.isMobileLogin() && StringUtils.equals(usernamePasswordToken.getMobileSign(),
				UsernamePasswordToken._MOBILE_SIGN_CIPHERTEXT)) {
			return true;
		} else {
			Object tokenHashedCredentials = hashProvidedCredentials(token, info);
			Object accountCredentials = getCredentials(info);
			return equals(tokenHashedCredentials, accountCredentials);
		}

	}

}
